﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
public partial class Dom操作_XML文件树形输出操作 : System.Web.UI.Page
{

    TongUse TextData = new TongUse();
    protected void Page_Load(object sender, EventArgs e)
    {
       tt.Text = SiteSetAddCloumns(Server.MapPath("treeout.xml"), "");

        //System.Xml.XmlDataDocument MyXMl = new System.Xml.XmlDataDocument();
        //MyXMl.LoadXml("<Column Name=\"添加栏目名称2\" Lx=\"栏目分类\" Fenlei=\"一级栏目\" dir=\"栏目目录\" pic=\" 栏目图片\" ItempAdderss=\"栏目模板地址\" itempParam=\"栏目模板参数\" Sort=\"栏目排序\" TabName=\"栏目英文名\"><![CDATA[ <br> 3]]></Column>");
    //   MyXMl.LoadXml("<![CDATA[ <br> 3]]>");
      //  Response.Write(MyXMl.DocumentElement.ChildNodes[0].OuterXml);

        Response.Write("<br/>sssss+" + SiteGetColumnLv(0));
    }


    /// <summary>
    /// 添加栏目的临时级别
    /// </summary>
    int SiteSetAddCloumnsCloumnLvTemp = 0;

    /// <summary>
    /// 添加栏目的临时ID
    /// </summary>
    int SiteSetAddCloumnsColumnsIDTemp = 0;

    /// <summary>
    /// 添加栏目函数
    /// </summary>
    /// <param name="xmlpath">XML栏目文件</param>
    /// <param name="XmlData">为空 "" </param>
    /// <returns></returns>
    public string SiteSetAddCloumns(string xmlpath,String XmlData)
    {
        System.Xml.XmlDataDocument MyXml = new System.Xml.XmlDataDocument();
        if (XmlData == "")
        {
            MyXml.Load(xmlpath);//得到XML数据
        }
        else
        {
            MyXml.LoadXml(XmlData);
        }
        
        for (int i = 0; i < MyXml.DocumentElement.ChildNodes.Count;i++ )
        {
           
            try
            {              //得到树状结构
                if (SiteSetAddCloumnsCloumnLvTemp == 0)
                {
                    //Response.Write("天始个在类栏目");
                   Response.Write(TextData.EStr(SiteSetAddCloumnsCloumnLvTemp, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;") + SiteSetAddCloumnsColumnsIDTemp + MyXml.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("Cont").Value + SiteSetAddCloumnsCloumnLvTemp + "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n<br/>");
                   // TextData.SqlDataSave("insert into [CC] (fid,CName) values(0,'" + MyXml.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("Name").Value + "') ");//加入栏目完成
                }
                else
                {
                    
                    Response.Write(TextData.EStr(SiteSetAddCloumnsCloumnLvTemp, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;") + SiteSetAddCloumnsColumnsIDTemp + MyXml.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("Cont").Value + SiteSetAddCloumnsCloumnLvTemp + "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n<br/>");
                    //如果是子栏目
                    string strxxx = TextData.SqlataSet("select * from [cc] where fid=0 order by id desc").Tables[0].Rows[0][0].ToString();//得到栏目ＩＤ
                    
                    
                }
                SiteSetAddCloumnsColumnsIDTemp += 1;
                SiteSetAddCloumnsCloumnLvTemp++;
                SiteSetAddCloumns(xmlpath, MyXml.DocumentElement.ChildNodes[i].OuterXml);//得到这个XML文件下的所有子节点
                SiteSetAddCloumnsCloumnLvTemp--;
            }
           catch(System.Xml.XmlException)//这里如是最下层就不进行下一次的调用自己了
            {
            }
        }
        return "";
    }


    /// <summary>
    /// 得到栏目级别
    /// </summary>
    int SiteGetColumnLv_ColumnLv = 0;

    //传入栏目ID 得到栏目级别
    public int SiteGetColumnLv(int ColumnID)
    {
        //如果不是一级栏目

    string SiteGetColumnLvsql;//sql语句
    SiteGetColumnLvsql = "select * from [cc] where fid=" + ColumnID + " order by id desc";
    DataTable ShowbokckTablue = new DataTable();
    ShowbokckTablue = TextData.SqlataSet(SiteGetColumnLvsql).Tables[0];

    /// <summary>
    /// 用于保存栏目的临时表
    /// </summary>
    for (int SiteGetColumnLvi = 0; SiteGetColumnLvi < ShowbokckTablue.Rows.Count; SiteGetColumnLvi++)
    {

        SiteGetColumnLv_ColumnLv++;
        SiteGetColumnLv(int.Parse(ShowbokckTablue.Rows[SiteGetColumnLvi]["fid"].ToString()));
        SiteGetColumnLv_ColumnLv--;

    }
            



        return SiteGetColumnLv_ColumnLv;
    }


}
